package com.collect.cameroon.zhiScene.zhiDs.zhiFollow;

import android.content.Context;

import com.collect.cameroon.zhiBase.BasePresenter;
import com.collect.cameroon.zhiBase.BaseSubscriber;
import com.collect.cameroon.zhiBean.zhiReceive.ZHIRDsListEntity;
import com.collect.cameroon.zhiBean.zhiSend.ZHISDsMarkedOrder;
import com.collect.cameroon.zhiBean.zhiSend.ZHISendEntity;
import com.collect.cameroon.zhiNetApi.ZHIHttpApiProvider;
import com.collect.cameroon.zhiNetApi.ZHIHttpResponse;
import com.collect.cameroon.zhiUtils.RxSchedulers;

import javax.inject.Inject;

public class ZHIDsFollowPresenter extends BasePresenter<ZHIDsFollowContract.View> implements ZHIDsFollowContract.Presenter {

    @Inject
    public ZHIDsFollowPresenter() {

    }

    @Override
    public void getLatestDsList(Context context, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse<ZHIRDsListEntity>> subscriber = new
                BaseSubscriber<ZHIHttpResponse<ZHIRDsListEntity>>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            ZHIRDsListEntity zhirDsListEntity = (ZHIRDsListEntity) object;
                            mView.onGetLatestDsList(zhirDsListEntity);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().dsOrderList(new ZHISendEntity())
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }

    @Override
    public void markDsOrder(Context context, ZHISDsMarkedOrder zhisDsMarkedOrder, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse> subscriber = new
                BaseSubscriber<ZHIHttpResponse>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            mView.onMarkDsOrder();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().markDsOrder(zhisDsMarkedOrder)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }
}
